package com.test.service.impl;

import com.test.entity.Test1;
import com.test.entity.Test2;
import com.test.service.Test1Service;
import com.test.service.Test2Service;
import com.test.service.Test3Service;
import com.test.service.TransactionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class TransactionServiceImpl implements TransactionService {
    @Resource
    Test1Service test1Service;

    @Resource
    Test2Service test2Service;

    @Resource
    Test3Service test3Service;

    @Override
    @Transactional
    public void test1() {
        test1Service.insertSelective(new Test1().setName("test1"));
        test1Service.test2();
        test2();
        throw new RuntimeException("出错拉");
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void test2() {
        test2Service.insertSelective(new Test2().setName("test1"));
    }

    @Override
    @Transactional
    public void test3() {

    }
}
